Skip to content

fix: preserve duplicate implicit output aliases#337

Open
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/microflow-variable-alias-collision
Open

fix: preserve duplicate implicit output aliases#337
hjotha wants to merge 2 commits intomendixlabs:mainfrom
hjotha:submit/microflow-variable-alias-collision

Conversation

@hjotha
Copy link
Copy Markdown
Contributor

@hjotha hjotha commented Apr 27, 2026

Summary

Preserves same-position duplicate implicit output variables by assigning deterministic local aliases such as Foo_2 and resolving downstream references to the active alias.

Part of #332.

Changes

  • Tracks implicit output positions in the microflow builder.
  • Assigns numeric aliases when a duplicate implicit output appears at the same canvas point.
  • Resolves downstream variable references, attribute paths, change targets, and retrieve start variables through the active alias.
  • Documents the aliasing behavior and adds a doctype fixture.

Validation

  • make build
  • make lint-go
  • make test
  • ./bin/mxcli check mdl-examples/doctype-tests/variable_alias_collision.test.mdl

Symptom: when a described microflow contained repeated implicit output variables at the same canvas position, rebuilding the MDL could reuse the first variable name for later activities and make downstream changes or returns point at the wrong object.

Root cause: the builder tracked variable declarations by name only and did not distinguish same-position duplicate implicit outputs that need a deterministic local alias.

Fix: record implicit output positions, assign numeric aliases such as `Foo_2` for same-position collisions, and resolve downstream variable references, attribute paths, change targets, and retrieve start variables through the active alias.

Tests: added a builder regression for duplicate create-object outputs, added a doctype fixture, and documented the aliasing rule in the proposal index and quick reference.
@github-actions
Copy link
Copy Markdown

AI Code Review

What Looks Good

  • The PR addresses a clear issue (duplicate implicit output variables breaking round-trip preservation) with a focused solution
  • Changes are isolated to the microflow builder logic without affecting other areas
  • Comprehensive test coverage includes both unit tests (cmd_microflows_builder_variable_alias_test.go) and doctype test (variable_alias_collision.test.mdl)
  • Documentation updates (MDL_QUICK_REFERENCE.md and new proposal) clearly explain the behavior
  • The aliasing logic correctly handles position-scoping, variable declaration checks, and reference resolution
  • Follows the project's validation process (build, lint, test passes)

Recommendation

Approve the PR. The changes are correct, well-tested, and properly documented. No blocking issues found.


Automated review via OpenRouter (Nemotron Super 120B) — workflow source

Adds an MDL script under mdl-examples/bug-tests/ exercising two
implicit `$Item` outputs at the same `@position(100, 200)`. The
describe → exec → describe fixpoint plus `mx check` (0 errors)
confirm the alias `$Item_2` is generated and downstream references
resolve through the active alias.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants